﻿using Shop.RemoteModel.LogisticsConfig;
using Shop.RemoteModel.LogisticsConfig.Model;
using Shop.StoreGatewayModular.Interface;
using Shop.StoreGatewayModular.Model.LConfig;
using WeDonekRpc.Client;
using WeDonekRpc.Helper.Area;
using WeDonekRpc.HttpApiGateway.Model;

namespace Shop.StoreGatewayModular.Service
{
    internal class LogisticsConfigService : ILogisticsConfigService
    {
        public void Delete ( long id )
        {
            new DeleteLConfig
            {
                Id = id
            }.Send();
        }
        public long Add ( LConfigAdd datum )
        {
            LogisticsConfigAdd add = datum.ConvertMap<LConfigAdd, LogisticsConfigAdd>();
            Area area = AreaHelper.GetArea(datum.AreaId);
            add.AreaName = area.Name;
            add.AreaType = area.AreaType;
            return new AddLConfig
            {
                Datum = add
            }.Send();
        }
        public bool Set ( long id, LogisticsConfigSet datum )
        {
            return new SetLConfig
            {
                Id = id,
                Datum = datum
            }.Send();
        }
        public LogisticsPrice Calculate ( CalculateLogisticsDto obj )
        {
            CalculateLogistics arg = obj.ConvertMap<CalculateLogisticsDto, CalculateLogistics>();
            arg.AreaId = AreaHelper.GetAreaId(obj.AreaId);
            return new CalculateLPrice
            {
                Datum = arg
            }.Send();
        }
        public bool SetIsEnable ( long id, bool isEnable )
        {
            return new SetLConfigIsEnable
            {
                Id = id,
                IsEnable = isEnable
            }.Send();
        }
        public LogisticsConfigDatum[] Gets ( LQueryParam query )
        {
            return new GetLConfigs
            {
                Query = query
            }.Send();
        }
        public PagingResult<LogisticsConfigDatum> Query ( PagingParam<LQueryParam> param )
        {
            return new QueryLConfig
            {
                Index = param.Index,
                Size = param.Size,
                SortName = param.SortName,
                IsDesc = param.IsDesc,
                NextId = param.NextId,
                QueryParam = param.Query
            }.Send();
        }
        public LogisticsConfigDatum Get ( long id )
        {
            return new GetLConfig
            {
                Id = id
            }.Send();
        }
    }
}
